

namespace WooEngine.Utility.Random
{
	public class RTGameRandomBase  {
		
		private  long seed;

	    private static long multiplier = 0x5DEECE66DL;
	    private static long addend = 0xBL;
	    private static long mask = (1L << 48) - 1;
		
		private double nextNextGaussian;
	    //private bool haveNextNextGaussian = false;
		
		public RTGameRandomBase(){
			
		}
		
		public RTGameRandomBase(long seed) {
	        SetSeed(seed);
	    }
		
		public void SetSeed(long seed) {
	        seed = (seed ^ multiplier) & mask;
	        this.seed = seed;
	  //  	haveNextNextGaussian = false;
	    }
		
		public int NextInt() {
			return Next(32);
	    }
		
		public int NextInt(int n) {
	        if (n <= 0)
	           	return 0;

	        if ((n & -n) == n)  // i.e., n is a power of 2
	            return (int)((n * (long)Next(31)) >> 31);

	        int bits, val;
	        do {
	            bits = Next(31);
	            val = bits % n;
	        } while (bits - val + (n-1) < 0);
	        return val;
	    }
		
		public long NextLong() {
	        return ((long)(Next(32)) << 32) + Next(32);
	    }
		
		public bool NextBoolean() {
			return Next(1) != 0;
	    }
		
		public float NextFloat() {
	        return Next(24) / ((float)(1 << 24));
	    }
		
		public double NextDouble() {
	        return (((long)(Next(26)) << 27) + Next(27))
		    / (double)(1L << 53);
	    }
		
		protected int Next(int bits) {
	        seed = (seed * multiplier + addend) & mask;
	        return (int)(seed >> (48 - bits));
	    }
	}

}